package de.wittje.games.mlpbd.view.windows;

import java.awt.event.KeyListener;

import javax.swing.JFrame;
import javax.swing.JPanel;

import de.wittje.games.mlpbd.controller.ExternalizingController;
import de.wittje.games.mlpbd.controller.SoundController;
import de.wittje.games.mlpbd.controller.listeners.OptionListener;
import de.wittje.games.mlpbd.controller.listeners.TitleListener;
import de.wittje.games.mlpbd.view.panels.OptionPanel;
import de.wittje.games.mlpbd.view.panels.TitlePanel;

public class MainWindow extends JFrame {

	private ExternalizingController ec;
	private JPanel content;
	private KeyListener listener;
	private SoundController sc;

	public MainWindow(ExternalizingController ec, int width, int height) {
		sc = new SoundController();

		this.ec = ec;
		setTitle(ec.getResource("title"));
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setSize(width, height);
		setLocationRelativeTo(null);
		content = new TitlePanel(ec, this);
		listener = new TitleListener((TitlePanel) content);
		addKeyListener(listener);
		add(content);
		setVisible(true);
		sc.playMusic("intro");

	}

	public void setContent(String type) {
		switch (type) {
		case "option":
			remove(content);
			content = new OptionPanel(ec, this);
			add(content);
			removeKeyListener(listener);
			listener = new OptionListener((OptionPanel) content);
			addKeyListener(listener);
			repaint();
			content.repaint();
		}
	}
}
